<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改学生信息</title>
    <script src="js/jquery-3.4.1.js"></script>
</head>
<body>
<form>
    学号：<input type="text" id="stuNo"/><br />
    姓名：<input type="text" id="stuName"/><br />
    性别：<select id="gender">
    <option value="男">男</option>
    <option value="女">女</option>
</select><br />
    班级：<select id="classes">
    <option value="1808011">1808011</option>
    <option value="1808012">1808012</option>
    <option value="1808021">1808021</option>
    <option value="1808022">1808022</option>
    <option value="1808031">1808031</option>
    <option value="1808032">1808032</option>
    <option value="1808041">1808041</option>
    <option value="1808042">1808042</option>
</select><br />
    院系：<select id="department">
    <option value="软件工程">软件工程</option>
    <option value="电子信息">电子信息</option>
    <option value="计算机科学与技术">计算机科学与技术</option>
    <option value="物联网">物联网</option>
</select><br />
    宿舍：<input type="text" id="dormNo"/><br />
    电话：<input type="tel" id="tel"/><br />
    <input type="button" id="submit" value="提交"/>
</form>
<script>
    $(function(){
        var stuNo=window.location.href.split("=")[1];
        $.ajax({
            "url":"http://localhost:8080/studentDemo/ListStudentByNoServlet",
            "data":{"stuNo":stuNo},
            async:false,
            success:function (response) {
                var student=JSON.parse(response);
                $("#stuNo").val(student.stuNo);
                $("#stuNo").attr("readOnly","readonly");
                $("#stuName").val(student.stuName);
                $("#tel").val(student.tel);
                $("#gender").val(student.gender);
                $("#dormNo").val(student.dormNo);
                $("#classes").val(student.classes);
                $("#department").val(student.department);
            }
        })
    });
    $("#submit").click(function () {
        if($("#stuName").val()=="" || $("#tel").val()=="" || $("#dormNo").val()==""){
            alert("信息填写不全！");
        }
        else{
            $.ajax({
                "url":"/studentDemo/UpdateStudentServlet",
                "data":
                    {
                        "stuNo":$("#stuNo").val(),
                        "stuName":$("#stuName").val(),
                        "classes":$("#classes").val(),
                        "department":$("#department").val(),
                        "gender":$("#gender").val(),
                        "tel":$("#tel").val(),
                        "dormNo":$("#dormNo").val()
                    },
                async:false,
                success:function (response) {
                    var data=JSON.parse(response);
                    switch (data.result) {
                        case "ok":
                            alert(data.msg);
                            window.location.href="listStudents.html";
                            break;
                        case "error":
                            alert(data.msg);
                            break;
                        default:
                            alert("出错啦!");
                            break;
                    }
                }
            })
        }

    })
</script>
</body>
</html>